package logger;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;

public class ProdutorWriter {

	@Produces
	public BufferedWriter criaWriter() {
		BufferedWriter bw = null;
		File file;
		try {
			if (System.getProperty("os.name").equals("Linux")){				
				file = new File("/home/norbert/logCdi.txt");
			}else{
				file = new File("d:\\logCdi.txt");
			}
			if (!file.exists()) {
				file.createNewFile();
			}

			FileWriter fw = new FileWriter(file,true);
			bw = new BufferedWriter(fw);

		} catch (IOException e) {
			e.printStackTrace();
		}
		return bw;
	}

	public void fechaWriter(@Disposes BufferedWriter bw) {
		try {
			bw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
